package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SetmealMapper {

    /**
     * 根据分类id查询套餐的数量
     * @param id
     * @return
     */
    @Select("select count(id) from setmeal where category_id = #{categoryId}")
    Integer countByCategoryId(Long id);
    /*
     * @description:新增套餐
     * @author: song
     * @date: 2024/1/2 14:41
     * @param: [setmeal]
     * @return: void
     **/
    @AutoFill(OperationType.INSERT)
    void insert(Setmeal setmeal);
    /*
     * @description:套餐分页查询
     * @author: song
     * @date: 2024/1/2 14:58
     * @param: [setmealPageQueryDTO]
     * @return: com.github.pagehelper.Page<com.sky.vo.SetmealVO>
     **/
    Page<SetmealVO> pageQuery(SetmealPageQueryDTO setmealPageQueryDTO);
    /*
     * @description:根据id查询套餐信息
     * @author: song
     * @date: 2024/1/2 15:18
     * @param: [id]
     * @return: com.sky.entity.Setmeal
     **/
    @Select("select  * from setmeal where id = #{id}")
    Setmeal getById(Long id);
    /*
     * @description:通过id删除套餐
     * @author: song
     * @date: 2024/1/2 15:20
     * @param: [setmealId]
     * @return: void
     **/
    @Delete("delete from setmeal where id = #{id}")
    void deleteById(Long setmealId);
    /*
     * @description:修改套餐
     * @author: song
     * @date: 2024/1/2 15:50
     * @param: [setmeal]
     * @return: void
     **/
    @AutoFill(OperationType.UPDATE)
    void update(Setmeal setmeal);
    /**
     * @description:动态条件查询套餐
     * @author: song 
     * @date: 2024/1/10 10:09
     * @param: [setmeal]
     * @return: java.util.List<com.sky.entity.Setmeal>
     **/
    List<Setmeal> list(Setmeal setmeal);
    /**
     * @description:根据id查询菜品选项
     * @author: song 
     * @date: 2024/1/10 10:10
     * @param: [setmealId]
     * @return: java.util.List<com.sky.vo.DishItemVO>
     **/
    @Select("select sd.name, sd.copies, d.image, d.description " +
            "from setmeal_dish sd left join dish d on sd.dish_id = d.id " +
            "where sd.setmeal_id = #{setmealId}")
    List<DishItemVO> getDishItemBySetmealId(Long setmealId);
}
